//
//  WeddingCarSkuView.m
//  BaseProject
//
//  Created by 王洋 on 2021/5/20.
//  Copyright © 2021 王洋. All rights reserved.
//

#import "WeddingCarSkuView.h"

@interface WeddingCarSkuView ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableview;

@property (nonatomic, strong) NSMutableArray <CommonSelSkuModel *>* dataArray;

@property (nonatomic, assign) NSInteger followNum;

@end

@implementation WeddingCarSkuView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self layout];
    }
    return self;
}

- (void)layout {
    
    [self addSubview:self.tableview];
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
}

- (void)fillViewWithArray:(NSMutableArray <CommonSelSkuModel *>*)dataArray andFollowNum:(NSInteger)followNum {
    self.followNum = followNum;
    self.dataArray = dataArray.mutableCopy;
    [self.tableview reloadData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 16;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    WeddingCarSkuCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WeddingCarSkuCellID"];
    cell.selectionStyle =UITableViewCellSelectionStyleNone;
    [cell fillCellWithModel:self.dataArray[indexPath.row] andfollowNum:self.followNum];
    return cell;
}

- (NSMutableArray<CommonSelSkuModel *> *)dataArray {
    if (!_dataArray) {
        _dataArray = @[].mutableCopy;
    }
    return _dataArray;
}

- (UITableView *)tableview {
    if (!_tableview) {
        _tableview = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableview.backgroundColor =  [UIColor whiteColor];
        
        _tableview.showsHorizontalScrollIndicator = NO;
        _tableview.showsVerticalScrollIndicator = NO;
        
        _tableview.estimatedSectionHeaderHeight = 0;
        _tableview.estimatedSectionFooterHeight = 0;
        _tableview.estimatedRowHeight = 0;
        
        [_tableview registerNib:[UINib nibWithNibName:@"WeddingCarSkuCell" bundle:nil] forCellReuseIdentifier:@"WeddingCarSkuCellID"];
    }
    return _tableview;
}

@end
